//
//  UpdNickerViewController.m
//  Dear
//
//  Created by n22 on 15/7/16.
//  Copyright (c) 2015年 陈俊俊. All rights reserved.
//

#import "UpdNickerViewController.h"

@interface UpdNickerViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *nickTextField;


@end

@implementation UpdNickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBA(246, 246, 246, 1);
    [self createTitleViewWith:@"修改昵称"];
}

#pragma mark - 保存按钮的事件
- (IBAction)saveBtn:(id)sender {
    
    
    NSString *nickName = [self.nickTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if (nickName.length == 0) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"请输入昵称" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    NSDictionary *dict = @{@"userId":[DearUser sharedInstance].userId,@"txtName":nickName};
    NSString *url = [ServerUrl stringByAppendingFormat:@"/%@",DearHttpModifyName];
    [[HttpRequest sharedInstance] POST:url parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [DearLoadingView hideHUD];
        if (responseObject) {
            NSDictionary *dict = (NSDictionary *)responseObject;
            if ([dict[@"Result"] integerValue] == 0)
            {
                [DearLoadingView showTips:dict[@"Message"]];
                [DearUser sharedInstance].txtName = nickName;
            }else {
                [DearLoadingView showTips:dict[@"Message"]];
            }
        }else{
            [DearLoadingView showTips:@"获取失败"];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [DearLoadingView hideHUD];
        [DearLoadingView showTips:error];
    }];
}

#pragma mark -收键盘
- (void)keyboardHidden
{
    [self.nickTextField resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
